//
//  PathViewController.m
//  Core Graphics Code
//
//  Created by liboxiang on 2019/1/10.
//  Copyright © 2019 liboxiang. All rights reserved.
//

#import "PathViewController.h"

@interface PathViewController ()

@end

@implementation PathViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    UIGraphicsBeginImageContext(self.view.bounds.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextMoveToPoint(context, 0, 100);
    //直线
    CGContextAddLineToPoint(context, 100, 100);
    
    CGPoint lines[] = {CGPointMake(150, 100),CGPointMake(200, 100),CGPointMake(200, 150),CGPointMake(180, 100),CGPointMake(300, 140),CGPointMake(250, 120),CGPointMake(300, 100),};
    CGContextAddLines(context, lines, sizeof(lines)/sizeof(lines[0]));
    
    //弧
    CGContextAddArc(context, 100, 200, 100, 0, M_PI, 0);
    CGContextAddArcToPoint(context, 50, 150, 300, 500, 100);
    
    //曲线
    CGContextAddCurveToPoint(context, 50, 500, 200, 500, 250, 400);
    CGContextAddQuadCurveToPoint(context, 100, 600, 200, 300);
    
    //闭合路径
    CGContextClosePath(context);
    
    //椭圆
    CGContextAddEllipseInRect(context, CGRectMake(50, 500, 100, 50));
    
    CGContextBeginPath(context);
    //矩形
    CGContextAddRect(context, CGRectMake(50, 500, 100, 50));
    CGRect rects[] = {CGRectMake(250, 500, 100, 50),CGRectMake(250, 600, 100, 50)};
    CGContextAddRects(context, rects, 2);
    
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextStrokePath(context);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.layer.contents = (id)image.CGImage;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
